// components/myData/mydata.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        data: {
            type: Array,
            detailList: []
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        income: '0.00',//收入
        payment: '0.00',//支出
        detail: [],//渲染列表
        time: '2022-01-01',//时间
        numTextColor : '#f00',//颜色
    },
    /**
     * 组件的方法列表
     */
    methods: {
        //获取时间判断
        bindTimeChange(e) {
            this.setData({
                time: e.detail.value
            })
            let res = this.data.data;
            // console.log(res, "value");

            let that = this;
            //时间，获取时间渲染
            for (let i = 0; i < res.length; i++) {
                let time = res[i].payment;
                // console.log(this.data.time, "time");
                // console.log(time);
                //时间相同则渲染数据
                if (time == this.data.time) {
                    that.setData({
                        detail: this.data.data
                    })
                    // console.log(detail,1111);
                    //收入与支出的份额
                    let earn = 0;
                    let pay = 0;
                    let color = "";
                    // console.log(typeof earn);
                    for (let i = 0; i < res.length; i++) {
                        // console.log(res[i].daily);
                        let dayily = res[i].daily;
                        if (dayily == "收入") {
                            let num = Number(res[i].money);
                            earn += num;
                            color = "#f00";
                            // console.log(earn, "收入");
                            // console.log("收入",color)
                            
                        }
                        if (dayily == "支出") {
                            let money = Number(res[i].money);
                            pay += money;
                            color = "#0f0";
                            // console.log("支出",color);
                            // console.log(pay, "支出");     
                        }
                        that.setData({
                            income: earn,
                            payment: pay,
                            numTextColor : color
                        })
                    }
                }
            }

        }
    }
})